package com.ruoyi.project.channel.businessInfoOrder.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.channel.businessInfoOrder.mapper.BusinessInfoOrderMapper;
import com.ruoyi.project.channel.businessInfoOrder.domain.BusinessInfoOrder;
import com.ruoyi.project.channel.businessInfoOrder.service.IBusinessInfoOrderService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 会员卡单 服务层实现
 * 
 * @author CAIN
 * @date 2024-10-15
 */
@Service
public class BusinessInfoOrderServiceImpl implements IBusinessInfoOrderService 
{
	@Autowired
	private BusinessInfoOrderMapper businessInfoOrderMapper;

	/**
     * 查询会员卡单信息
     * 
     * @param userId 会员卡单ID
     * @return 会员卡单信息
     */
    @Override
	public BusinessInfoOrder selectBusinessInfoOrderById(Long userId)
	{
	    return businessInfoOrderMapper.selectBusinessInfoOrderById(userId);
	}
	
	/**
     * 查询会员卡单列表
     * 
     * @param businessInfoOrder 会员卡单信息
     * @return 会员卡单集合
     */
	@Override
	public List<BusinessInfoOrder> selectBusinessInfoOrderList(BusinessInfoOrder businessInfoOrder)
	{
	    return businessInfoOrderMapper.selectBusinessInfoOrderList(businessInfoOrder);
	}
	
    /**
     * 新增会员卡单
     * 
     * @param businessInfoOrder 会员卡单信息
     * @return 结果
     */
	@Override
	public int insertBusinessInfoOrder(BusinessInfoOrder businessInfoOrder)
	{
	    return businessInfoOrderMapper.insertBusinessInfoOrder(businessInfoOrder);
	}
	
	/**
     * 修改会员卡单
     * 
     * @param businessInfoOrder 会员卡单信息
     * @return 结果
     */
	@Override
	public int updateBusinessInfoOrder(BusinessInfoOrder businessInfoOrder)
	{
		if(businessInfoOrder.getDaySum().equals(0)) {
			String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
			businessInfoOrder.setBatch(time);
		}
	    return businessInfoOrderMapper.updateBusinessInfoOrder(businessInfoOrder);
	}

	/**
     * 删除会员卡单对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteBusinessInfoOrderByIds(String ids)
	{
		return businessInfoOrderMapper.deleteBusinessInfoOrderByIds(Convert.toStrArray(ids));
	}

	/**
	 * 重置刷单数
	 */
	@Override
	public int resetDaySum(){
		return businessInfoOrderMapper.resetDaySum();
	}
}
